package util;

import collection.ALinkedList;
import collection.ANode;

public class ListUtil {
	
	public static <N extends ANode<T>, T> boolean containsCycle(ALinkedList<N, T> llist)
	{
		if (llist.isEmpty())
		{
			return false;
		}
				
		N slowNode = llist.getFirst();
		N fastNode = llist.getNext(llist.getFirst());
		while(slowNode != null && fastNode != null)
		{
			if (slowNode == fastNode)
			{
				return true;
			}
			
			slowNode = llist.getNext(slowNode);
			fastNode = llist.getNext(llist.getNext(fastNode));
		}
		
		return false;
	}

}
